<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{$pagetitle}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/admin/style/global.css" media="all">
</head>
<body>


  <form class="layui-form" action="{:url()}" method="post" onsubmit="return save_form(this,success_fun)" style="padding-top: 10px;">
	<input type="hidden" name="catid" value="{$cat.catid}">
	<input type="hidden" name="modelid" value="{$cat.modelid}">
	<input type="hidden" name="pubid" value="2013{$cat.modelid}"><!--注意这里pubid是前面固定几个数+模型ID-->	  
    <div class="layui-form-item">
      <label class="layui-form-label">目标栏目</label>
		<div class="layui-input-block">
		  <input type="radio" name="cat_type" lay-filter="cat_type" value="selfCheck" title="当前选中的栏目" checked>
		  <input type="radio" name="cat_type" lay-filter="cat_type" value="catName" title="数据包中的栏目名称">
		  <input type="radio" name="cat_type" lay-filter="cat_type" value="catid" title="数据包中的catid">
		  <span class="layui-badge tips" title="只导入一个栏目的时候选择[当前选中的栏目即可],当导入到多个栏目的时候要判断是否有重名的栏目名称,如果有重名的建议选择[数据包中的catid],否则可能会导入到错误的栏目中去.">?</span>
		</div>
    </div>
    <div class="layui-form-item cat_select">
      <label class="layui-form-label">选择栏目</label>
      <div class="layui-input-inline">
        <select style="width:400px" name="target_catid" class="select2" lay-ignore><option value="">请选择目标栏目</option>{$catInc|raw}</select>
      </div>
    </div>
    <div class="layui-form-item cat_select2" style="display: none;">
      <label class="layui-form-label">栏目结构</label>
      <div class="layui-input-inline">
        <a href="{:url('cat/index',['modelid'=>$cat['modelid']])}" target="_blank" style="color:#28b779;font-weight: 600; line-height: 36px; text-decoration: underline">查看所有栏目结构</a>
      </div>
    </div>	
    <div class="layui-form-item">
      <label class="layui-form-label" >重复字段检测</label>
		<div class="layui-input-block">
			<div style="float: left; padding-top: 10px;">当遇到重复的字段
			<select style="width:80px" name="check_fieldName" lay-ignore>
				{foreach $modelIndexField as $v}
				<option value="{$v.field}">{$v.name}</option>
				{/foreach}
			</select>如何处理：</div>
		  <input type="radio" name="check_title" value="update" title="更新" checked>
		  <input type="radio" name="check_title" value="continue" title="跳过">
		  <input type="radio" name="check_title" value="add" title="重复添加">
		  <span class="layui-badge tips" title="系统会根据你选择的字段做验证,如果当数据表里已存在完全相同的记录,会根据你的处理要求做业务处理.">?</span>
		</div>		
    </div>	
    <div class="layui-form-item">
      <label class="layui-form-label">要导入的字段</label>
		<div class="layui-input-block">
			{foreach $modelAllField as $v}
				<input type="checkbox" name="import_field" value="{$v.field}" title="{$v.name}" checked>
			{/foreach}
		</div>
    </div>	
    <div class="layui-form-item">
	  <label class="layui-form-label" style="padding-top: 0px;">数据包<span>导入前请先下载模板</span></label>
	  <div class="layui-input-inline file-upload" style="width: 80%;">
			<input type="text" name="file" id="info_file" autocomplete="off" class="layui-input modelform_file" style=""/>
			<div class="layui-btn-group">
				<button type="button" class="layui-btn" onclick="GetImportExcelDemo();"><i class="layui-icon">&#xe601;</i>下载模板</button>
				<button type="button" class="layui-btn fastupimg" data-input_id="info_file" data-listtype="file" id="info_file_Picker"><i class="layui-icon">&#xe608;</i>上传</button>
				<button type="button" class="layui-btn" onClick="selectfile('info_file','','file')"><i class="layui-icon">&#xe67c;</i>浏览</button>
			</div>
	  </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">导入的数据是否需要审核</label>
		<div class="layui-input-block">
		  <input type="radio" name="state" value="checked" title="直接审核" {if $Request.param.state=="checked"}checked{/if}>
		  <input type="radio" name="state" value="readyCheck" title="待审核" {if $Request.param.state=="readyCheck"}checked{/if}>
		  <input type="radio" name="state" value="draft" title="草稿" {if $Request.param.state=="draft"}checked{/if}>
		</div>
    </div>
	
	<div class="layui-form-item">
		<div class="layui-input-block">
		  <button class="layui-btn" type="submit" type="submit" onclick="$('.layui-form').attr('action','{:url()}');$('.layui-form').submit();" lay-filter="component-form-element">开始导入</button>
		  <button type="reset" class="layui-btn layui-btn-primary close">关闭</button>
		</div>
	</div>
  </div>
	</form>
	
<div class="layui-card-body">
	<table class="layui-table export_result"></table>	
</div>
  <!--文件上传ajax调用的接口地址-->
  <script>
    var upload_index="{:url('file/index')}";
    var upload_add="{:url('file/add')}";
    var upload_config="{:url('file/uploadConfig')}";
  </script>
  <script src="/static/admin/layui/layui.js"></script>
  <script src="/static/js/jquery.min.js"></script>    
  <script src="/static/js/globals.js"></script>  
  <!--select2 js start-->
  <link rel="stylesheet" href="/static/select2/select2.css" media="all">
  <script src="/static/select2/select2.js"></script>
  <!--select2 js end-->
<!--文件上传 start-->
<script type="text/javascript" src="/static/webuploader/kinderfile.js"></script>
<script type="text/javascript" src="/static/webuploader/Sortable.js"></script>    
<script type="text/javascript" src="/static/webuploader/morepic.js"></script>   


<!--以下是针对 快速上传单个文件插件-->  
<link rel="stylesheet" type="text/css" href="/static/webuploader/style/webuploader.css" />
<link rel="stylesheet" type="text/css" href="/static/webuploader/style/style.css" />
<script type="text/javascript" src="/static/webuploader/webuploader.js"></script>
<script type="text/javascript" src="/static/webuploader/fastupimg.js"></script>
<!--文件上传 end-->
<!--文件上传的预览功能中中也需要用到我 fancybox plus start-->
<link rel="stylesheet" type="text/css" href="/static/fancybox3/jquery.fancybox.min.css" media="screen" />		

<script type="text/javascript" src="/static/fancybox3/jquery.fancybox.min.js"></script>
<!--文件上传的预览功能中中也需要用到我 fancybox plus end-->  
  <script>
  layui.config({
    base: '/static/admin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,element = layui.element
	,form = layui.form;

	$('.select2').select2();
	form.on('radio(cat_type)', function(data){
		if(data.value=="selfCheck"){
			$(".cat_select").show();
			$(".cat_select2").hide();
		}else{
			$(".cat_select").hide();
			$(".cat_select2").show();
		}
	}); 

  }); 
	function GetImportExcelDemo(){
		var modelid=$("input[name='modelid']").val();
		var cat_type=$("input:radio[name='cat_type']:checked").val();
		//遍历，用逗号串联 
		var import_field="";
		$("input:checkbox[name='import_field']:checked").each(function() { 
			import_field += this.value + ','; 
		}); 
		window.open("{:url('model/GetImportExcelDemo')}?modelid="+modelid+"&cat_type="+cat_type+"&import_field="+import_field);
		
	}	
	//导入成功后的回调
	function success_fun(data){
        var str="";
        for(var r in data){
            if(r==0){
                var str1="<thead><tr>";
            }else{
                var str1="<tr>";
            }          
            for(var r2 in data[r]){
                if(r==0){
                    str1=str1+"<th class='first'><div>"+data[r][r2]+"</div></th>";
                }else{
                    if(data[r][r2]=="导入成功"){
                        str1=str1+"<td class='tab-title'><div><a href='{:url("Info/update")}?catid="+data[r]['catid']+"&id="+ata[r]['id']+"' target='_blank'>"+data[r][r2]+"</a></div></td>";
                    }else{
                        str1=str1+"<td><div>"+data[r][r2]+"</div></td>";
                    }
                    
                }
            }
            if(r==0){
                str1=str1+"</tr></thead>";
            }else{
                str1=str1+"</tr>";
            }                          
            str=str+str1;
        }  
        $(".export_result").html(str);
	}
  </script>
</body>
</html>